package com.docman.dbconnect;
import java.sql.*;
import java.util.*;
public class ConnectionManager {

	
	
	private String className ="com.mysql.jdbc.Driver";
	private String userName ="DOCMANAGER";
	private String password="123456";
	private String url ="jdbc:mysql://localhost:3306/";
	private static ConnectionManager connectionInstance = null;
	private String dbName = "docman";
	private String utfConfig ="?useUnicode=true&characterEncoding=UTF-8";
	
public ConnectionManager(){
//do not return an instance.	
}


public static synchronized ConnectionManager getInstance() {
	if(connectionInstance == null) {
	  connectionInstance = new ConnectionManager(); 		
	}
	return connectionInstance;
}


public Connection getConnection(){
	  
	  Connection conn = null;
	  try {
		  Class.forName(className);
		  conn = DriverManager.getConnection (url+dbName+utfConfig, userName, password);
		
		  System.out.println("Connection Established");
	  }  catch (ClassNotFoundException e) {
		  e.printStackTrace();
	  }	 catch (SQLException e) {
		  e.printStackTrace();
	  }
	  return conn;
}


public void closeConnection(Connection conn){
	  try {
		  conn.close();
	  } catch (SQLException e) {
		  e.printStackTrace();
	  }
} 
}
